﻿CREATE PROCEDURE dbo.StoreSensorTelegram
  @SensorId bigint,
  @HSEQ tinyint,
  @ORG tinyint,
  @Data0 tinyint,
  @Data1 tinyint,
  @Data2 tinyint,
  @Data3 tinyint,
  @Status tinyint,
  @Created datetimeoffset(7)
AS
begin transaction

  if not exists (select Id from Sensor where Id = @SensorId)
    begin
      insert Sensor (Id, Name) values (@SensorId, 'Unnamed')
    end 

  insert SensorTelegram (SensorId, HSEQ, ORG, Data0, Data1, Data2, Data3, Status, Created)
  values (@SensorId, @HSEQ, @ORG, @Data0, @Data1, @Data2, @Data3, @Status, @Created)
	
commit